<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>from() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>from()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>from()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/displaying/from/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/04-displaying/03-from.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().from(Moment|String|Number|Date|Array);
moment().from(Moment|String|Number|Date|Array, Boolean);
</code></pre>

							</div>
<p>&#x53EF;&#x80FD;&#x60F3;&#x8981;&#x663E;&#x793A; moment &#x4E0E;&#x73B0;&#x5728;&#x4EE5;&#x5916;&#x7684;&#x65F6;&#x95F4;&#x7684;&#x76F8;&#x5BF9;&#x65F6;&#x95F4;&#x3002;
&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>moment#from</code>&#x3002;</p>
<pre><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.from(b) // &quot;1 &#x5929;&#x524D;&quot;
</code></pre>
<p>&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x53EF;&#x4EE5;&#x4F20;&#x7ED9; <code>moment()</code> &#x7684;&#x4EFB;&#x4F55;&#x503C;&#x6216;&#x5B9E;&#x9645;&#x7684; <code>Moment</code>&#x3002;</p>
<pre><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.from(b);                     // &quot;1 &#x5929;&#x524D;&quot;
a.from([2007, 0, 29]);         // &quot;1 &#x5929;&#x524D;&quot;
a.from(new Date(2007, 0, 29)); // &quot;1 &#x5929;&#x524D;&quot;
a.from(&quot;2007-01-29&quot;);          // &quot;1 &#x5929;&#x524D;&quot;
</code></pre>
<p>&#x4E0E; <code>moment#fromNow</code> &#x4E00;&#x6837;&#xFF0C;&#x5C06; <code>true</code> &#x7528;&#x4F5C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x8FD4;&#x56DE;&#x4E0D;&#x5E26;&#x540E;&#x7F00;&#x7684;&#x503C;&#x3002;
&#x65E0;&#x8BBA;&#x4F55;&#x65F6;&#x9700;&#x8981;&#x6709;&#x53EF;&#x8BFB;&#x7684;&#x65F6;&#x95F4;&#x957F;&#x5EA6;&#xFF0C;&#x8FD9;&#x90FD;&#x975E;&#x5E38;&#x6709;&#x7528;&#x3002;</p>
<pre><code class="language-javascript">var start = moment([2007, 0, 5]);
var end   = moment([2007, 0, 10]);
end.from(start);       // &quot;5 &#x5929;&#x5185;&quot;
end.from(start, true); // &quot;5 &#x5929;&quot;
</code></pre>
<p>&#x4ECE; <strong>2.10.3</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x5982;&#x679C;&#x4EFB;&#x4E00;&#x7AEF;&#x70B9;&#x65E0;&#x6548;&#xFF0C;&#x5219;&#x7ED3;&#x679C;&#x4E3A;&#x672C;&#x5730;&#x5316;&#x7684;&#x65E0;&#x6548;&#x65E5;&#x671F;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().from(Moment|String|Number|Date|Array);
moment().from(Moment|String|Number|Date|Array, Boolean);
</code></pre>

							</div>
<p>You may want to display a moment in relation to a time other than now. In that case, you can use <code>moment#from</code>.</p>
<pre><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.from(b) // &quot;a day ago&quot;
</code></pre>
<p>The first parameter is anything you can pass to <code>moment()</code> or an actual <code>Moment</code>.</p>
<pre><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.from(b);                     // &quot;a day ago&quot;
a.from([2007, 0, 29]);         // &quot;a day ago&quot;
a.from(new Date(2007, 0, 29)); // &quot;a day ago&quot;
a.from(&quot;2007-01-29&quot;);          // &quot;a day ago&quot;
</code></pre>
<p>Like <code>moment#fromNow</code>, passing <code>true</code> as the second parameter returns value without the suffix. This is useful wherever you need to have a human readable length of time.</p>
<pre><code class="language-javascript">var start = moment([2007, 0, 5]);
var end   = moment([2007, 0, 10]);
end.from(start);       // &quot;in 5 days&quot;
end.from(start, true); // &quot;5 days&quot;
</code></pre>
<p>From version <strong>2.10.3</strong>, if any of the endpoints are invalid the result is the
localized Invalid date string.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>